<html>
<head>
	<title>XNova Redesigned Install</title>
	<link rel="shortcut icon" href="favicon.ico" />
	<link rel="stylesheet" type="text/css" href="styles.css" />
	<meta http-equiv="content-type" content="text/html" />

	<script type="text/javascript">
		//object detection to return the correct object depending upon browser type. Used by the getAXHA(); function.
		function getNewHttpObject() {
			 var objType = false;
			 try {
				  objType = new ActiveXObject('Msxml2.XMLHTTP');
			 } catch(e) {
				  try {
						objType = new ActiveXObject('Microsoft.XMLHTTP');
				  } catch(e) {
						objType = new XMLHttpRequest();
				  }
			 }
			 return objType;
		}

		//Function used to update page content with new xhtml fragments by using a javascript object, the dom, and http.
		function getAXAH(url,elementContainer,dofunction){
			if (typeof dofunction == "undefined") { dofunction = false; }

			var theHttpRequest = getNewHttpObject();
			theHttpRequest.onreadystatechange = function() {processAXAH(elementContainer,dofunction);};
			theHttpRequest.open("GET", url);
			theHttpRequest.send(false);

				function processAXAH(elementContainer,dofunction){
					if (theHttpRequest.readyState == 4) {
						if (theHttpRequest.status == 200) {
							document.getElementById(elementContainer).innerHTML = theHttpRequest.responseText;
							if(dofunction){ setTimeout(dofunction,0); }
						} else {
							document.getElementById(elementContainer).innerHTML="<p><span class='redtxt'>Error!<\/span> HTTP request return the following status message:&nbsp;" + theHttpRequest.statusText +"<\/p>";
						}
					}
				}
		}

		//Test connection
		function test_connection(){
			document.getElementById('testbutton').value = 'Connecting...';

			url = './install.php?page=checkconnection&server='+document.details.server.value+'&name='+document.details.dbname.value+'&user='+document.details.username.value+'&pass='+document.details.password.value;

			getAXAH(url,'ajaxdata','test_result()');
		}

		//Test result of last function
		function test_result(){
			l = document.getElementById('ajaxdata').innerHTML
			//alert(l)

			if(l == '0'){
				alert('Database settings are fine.');
				window.location.replace('./install.php?page=3');
			}else if(l == '1'){
				alert('Cannot connect to the database.');
				document.getElementById('testbutton').value = '>> Next';
			}else if(l == '3'){
				alert('Specified table does not exist and could not be created.');
				document.getElementById('testbutton').value = '>> Next';
			}else if(l == '2'){
				alert('Cannot write to config1.php. Please set CHMOD of this file to 777.');
				document.getElementById('testbutton').value = '>> Next';
			}else{
				alert('Unexpected value was returned.');
				document.getElementById('testbutton').value = '>> Next';
			}
		}

		function checkurl(url){
			//Load the url
			getAXAH('./install/here.php?url='+window.location,'url','checkurl(true)');

			//Are we meant to check it
			if(url){
				//Check it, if it exists
				if(window.location != document.getElementById('url').innerHTML && document.getElementById('url').innerHTML != ''){
					//Alert
					document.getElementById('alert').innerHTML = 'Your BASE URL is not configured properly. Please open game/SETUP.PHP and configure it there.<br>BASEURL value:<br>'+document.getElementById('url').innerHTML+'<br>This is usually caused by the game not being installed to the root directory';
					//Disable button
					document.getElementById('testbutton').disabled = true;
				}else{
					//Remove Alert
					document.getElementById('alert').innerHTML = '';
					//Enable button
					document.getElementById('testbutton').disabled = false;				
				}
			}
		}
	</script>

</head>

<body onLoad="checkurl(false);">
<span style="display:none;" id="url"></span>
<center>

	<img src="./images/xnovaproject.png" /><br />
	<img src="./install/stage2.png" /><br /><br />

	<div class="box">
		<div class="header">Installation</div>
		<div class="main">
			<span class="content">
				<span style="display:none;" id="ajaxdata"></span>
				You need to connect XNova Redesigned to your database.<br />
				Enter the details into the form below and click on connect.<br />
				<form name="details">
					<table>
						<tr>
							<td>Server address:</td>
							<td><input type="text" name="server" value="localhost" /></td>
						</tr>

						<tr>
							<td>Database Name:</td>
							<td><input type="text" name="dbname" /></td>
						</tr>

						<tr>
							<td>Account username:</td>
							<td><input type="text" name="username" /></td>
						</tr>

						<tr>
							<td>Account password:</td>
							<td><input type="password" name="password" /></td>
						</tr>
					</table>
				</form>
				Press next to test your settings and continue.<br /><br />

				<input type="button" id="testbutton" disabled="true" onClick="test_connection()" value=">> Next" /><br /><br />

				<span color="#FF0000" id="alert"></span>
			</span>
		</div>
		<div class="footer" />
	</div>

</center>
</body>
</html>
